/*The MIT License

Copyright (c) <2008> <Samir Menon>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#pragma once

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <boost/random.hpp>
#include "neurontools.h"
#include "CSpikeSpooler.h"
#include "CSystemClock.h"
#include "CSynapse.h"


namespace bis_neuron
{
	using namespace std;
	
	#define RESTING_POTENTIAL 0.1
	#define VM_MAX 10.0
	#define VM_MIN 0.0
	#define SCALING_FACTOR 0.1	
	#define DEFAULT_R 1.0
	class CNeuron
	{
	protected:
		int neuron_id;
		float vm, v_na;
		float vm_max,vm_min;
		float r;
		
		int execution_flag;
		bool log_data_flag, log_spike_flag;
		CSpikeSpooler *data_spooler, *spike_spooler;
		
		stringstream data_log_stream;
		CSystemClock* clock;	
		
	public:		
		virtual ~CNeuron();
		CNeuron();		
		
		virtual void initialize(int neuron_id, 
				CSpikeSpooler * arg_spike_spool, CSpikeSpooler * arg_data_spool)	{				};
		virtual bool fire(){return false;};
		virtual bool update_vm(){return false;};
		void reset_neuron()
		{	vm = 0.0; v_na = 0.0;	}
		void set_data(const float & arg_r){r = arg_r;}
		
		//Set current
		inline void set_r(float arg_r){	r = arg_r;	}		
		//Execution Flag Wrappers
		inline void set_exec_flag_on() { execution_flag=1;}
		inline void set_exec_flag_off() { execution_flag=0;}
		inline int get_exec_flag() { return execution_flag;}
		
		//Logging functions
		void set_data_logging(CSpikeSpooler* arg_data_spool);
		void log_data(); //Basic: vm - Each neuron class should extend this		
		inline void set_data_log_flag_on() { log_data_flag=true;}
		inline void set_data_log_flag_off() { log_data_flag=false;}
		inline bool get_data_log_flag() { return log_data_flag;}
		
		void set_spike_logging(CSpikeSpooler* arg_spike_spool);
		void log_spike();		
		inline void set_spike_log_flag_on() { log_spike_flag=true;}
		inline void set_spike_log_flag_off() { log_spike_flag=false;}
		inline bool get_spike_log_flag() { return log_spike_flag;}
		
	};
}
